package com.test.multithread.juc;

import java.util.HashMap;
import java.util.Map;
public class MyExecuteThreadLocalContext {
    //让ThreadLocal里面有一个默认的类即在初始化时 new 出来
    protected final static ThreadLocal<Map<Object, Object>> threadContext = new MapThreadLocal();
    private static class MapThreadLocal extends ThreadLocal<Map<Object, Object>> {
        @Override
        protected Map<Object, Object> initialValue() {
            HashMap<Object, Object> objectObjectHashMap = new HashMap<>();
            objectObjectHashMap.put("1", "1234567890");
            objectObjectHashMap.put("2", "1234567890");
            return objectObjectHashMap;
        }
    }
    private ThreadLocal<HashMap<Object, Object>> times = ThreadLocal.withInitial(() -> {
        HashMap<Object, Object> objectObjectHashMap = new HashMap<>();
        objectObjectHashMap.put("1", "1234567890");
        objectObjectHashMap.put("2", "1234567890");
        return objectObjectHashMap;
    });
    public static void main(String[] args) {
        Map<Object, Object> objectObjectMap = threadContext.get();
        System.out.println(objectObjectMap);
    }
}